package com.googlecode.framework.web.user;

public class LoginUserHolder {

    private LoginUserHolder() {
    }

    // 存储User副本
    private static ThreadLocal<UserObject> USER_CONTEXT = new ThreadLocal<UserObject>();

    public static UserObject getCurrentUser() {
        return USER_CONTEXT.get();
    }
    
    public static <T extends UserObject> T getCurrentUser(Class<T> userClass) {
        return userClass.cast(USER_CONTEXT.get());
    }

    public static <T extends UserObject> void setCurrentUser(T user) {
        if (user != null) {
            USER_CONTEXT.set(user);
        }
    }

    public static void removeCurrentUser() {
        USER_CONTEXT.remove();
    }
}
